﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace ProjetoFinal
{
    // FAZER fases
    // COLISÃO E PONTO COM AS FRUTAS


    public class MyGame
    {
        public MyGame(KeyboardState nowKeybord, KeyboardState oldKeyboard)
        {

        }

        Leaf leaf;
        Monckey monckey;
        CollisionManager collisionManager;
        public int life;
        bool lostLife = false;
        List<Texture2D> listofLives = new List<Texture2D>();
        Texture2D gameslife;
        public List<Fruit> fruits = new List<Fruit>();
        Random rnd = new Random();
        int drawn; // sorteado
        public static bool won;

        public void Initialize()
        {
            leaf = new Leaf(5, new Rectangle(360, 700, 305, 60), new Rectangle(360, 677, 305, 91));
            // fazer 2 rects, um pra desenhar e um pra colidir.
            monckey = new Monckey(new Rectangle(360,544, 200,196), new Vector2(5,5));
            collisionManager = new CollisionManager();
            life = 3;
            won = false;
        }

        public void LoadContent(ContentManager content)
        {
            leaf.LoadContent(content);
            monckey.LoadContent(content);
            gameslife = content.Load<Texture2D>("monckeybutton");
            drawn = rnd.Next(6);
            
            for (int i = 0; i <= 3; i++)
            {
                listofLives.Add(gameslife);
            }
        }

        

        public void Update(KeyboardState nowKeybord, KeyboardState oldKeyboard)
        {
            
            monckey.Move();
            leaf.Move(nowKeybord, oldKeyboard);
            collisionManager.Collision(leaf, monckey);

            if (nowKeybord.IsKeyDown(Keys.Escape))
                Manager.nowState = Manager.GameState.Quit;


            if (life > 0)
            {
                monckey.BackToPosition(ref life, ref lostLife);
                leaf.BackToPosition(ref lostLife);
            }

            if (life == 0)
            {
                won = false;
                Manager.nowState = Manager.GameState.youLost;
            }

            switch (drawn)
            {
                case 1:
                    fruits.Add(new Banana(new Rectangle(/* colocar aqui o valor sorteado */), "banana", 3));
                       break;
                case 2:
                       break;
                case 3:
                       break;
                case 4:
                       break;
                case 5:
                      break;

            }

            
        }

       
        public void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Begin();
            leaf.Draw(spriteBatch);
            monckey.Draw(spriteBatch);

            if (life > 0)
            {
                for (int i = 0; i < life; i++)
                {
                    spriteBatch.Draw(gameslife, new Vector2(980 - (50 * i), 10), Color.White);
                }
            }

         

            spriteBatch.End();
        }

        public void Restart()
        {
            life = 3;
            won = false;
        }

    }
}
